package com.activenetwork.smlite.testcase.events.createEvents.basics;

import java.io.IOException;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;

import com.activenetwork.schema.testcase.events.createevents.basics.basics020.Basics020DataType;
import com.activenetwork.smlite.business.EventBusiness;
import com.activenetwork.smlite.page.generic.ModelPage;
import com.activenetwork.smlite.testcase.BaseCase;
import com.activenetwork.util.EnvContext;
import com.activenetwork.util.PageLoader;
import com.activenetwork.util.jaxb.ScriptDataBindHelper;
import com.activenetwork.util.verification.gson.FailurePoint;

public class Basics020 extends BaseCase{
	static final Logger logger = LoggerFactory.getLogger(Basics020.class);
	private EventBusiness eventBusiness = new EventBusiness();
	private Basics020DataType data;
	
	@BeforeClass(alwaysRun = true)
	public void dataSetup(){		
		try{
			ScriptDataBindHelper helper = new ScriptDataBindHelper(Basics020.class);
			data = helper.bind(Basics020DataType.class);
		}catch(IOException e){
			throw new RuntimeException("Unable to bind the script data for " + this.getClass().getName());
		}
	}
	
	@Test
	public void Check_user_can_create_one_day_Event_successfully(){	
		loginBusiness.login();
		
		try{
			eventBusiness.deleteEvent("Helen Test One Day Event_20120912", data.getEvent());
		}catch(RuntimeException e){
			logger.info("No need to delete the event since it is not exist");
		}
		
		eventBusiness.addEventUI(data.getEvent());
		PageLoader.load(ModelPage.class).events();
		
		// Search the added one-day event
		try{
			eventBusiness.searchEvent("Helen Test One Day Event_20120912", data.getEvent());
		}catch(RuntimeException e){
			EnvContext.failurePointTL.get().add(
					new FailurePoint(Basics020.class.getName(), 
					"Verify create one-day event", 
					"Create one-day event failed"));
		}finally{
			loginBusiness.logout();
		}
	}
}
